package com.cms.template.method;

import com.cms.utils.FreeMarkerUtils;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
 * 模板方法 - 交集
 *
 *
 *
 */
@Component
public class IntersectionMethod implements TemplateMethodModelEx {

    /**
     * 执行
     *
     * @param arguments
     *            参数
     * @return 结果
     */
    @SuppressWarnings("rawtypes")
    public Object exec(List arguments) throws TemplateModelException {
        List<String> list1 = FreeMarkerUtils.getArgument(0, List.class, arguments);
        List<String> list2 = FreeMarkerUtils.getArgument(1, List.class, arguments);
        if(CollectionUtils.isNotEmpty(list1) && CollectionUtils.isNotEmpty(list2)){
            Collection list = CollectionUtils.intersection(list1, list2);
            if(CollectionUtils.isNotEmpty(list)){
                return true;
            }
        }
        return false;
    }
}
